steps360=400.0
degperstep=360.0 / steps360
TIMERPERIOD=1.0e-7
tregmin=65535
totaltime=3.0
n1=50
n2=150
t1=(n1*totaltime) /(n1+n2)
t2=(n2*totaltime) /(n1+n2)
#vi=0
vi = degperstep / (TIMERPERIOD * tregmin)
vf=1440.0
#j=(vf - vi) / (((t1+t2) - t1 + 1) * t1)
j=(vf - vi) / ((t1**2/2) + (t1*(t2-t1)) + (t1**2/2)) # or (vf - vi) / (t2*t1)
a(t) = (t < t1) ? j * t : (t < t2) ? j * t1 : j*(t1 - (t - t2))
#plot [t=0:5] a(t)   
v(t) = vi + ((t < t1) ? j * (t**2 /2) : (t < t2) ? j * t1 * (t - t1) + (j*t1**2/2) : j * ( t1 *(t - t2) - ((t - t2)**2/2)) + j*t1*(t2 -  t1) + (j*t1**2/2))
#set y2range [0:2*j*t1]
#set y2tics border
#plot [t=0:(t1+t2)] a(t) axis x1y2, v(t)   
p(t) = (vi *t) + ((t < t1) ? j * (t**3 /6) : (t < t2) ? j * t1 * ((t - t1)**2/2) + ((j*t1**2/2) * (t - t1) + (j*t1**3/6)) : \
        j * ( t1 *((t - t2)**2/2) - ((t - t2)**3/12)) + (j*t1*(t2-t1) +  (j*t1**2/2))*(t-t2) + \
        j * t1 * ((t2 - t1)**2/2) + ((j*t1**2/2) * (t2 - t1) + (j*t1**3/6)))
step(t)=p(t)/degperstep
#set y2range [0:2*j*t1]
#set y2tics border
#plot [t=0:(t1+t2)] a(t) axis x1y2, v(t), step(t)
#set parametric
#plot [t=0:(t1+t2)] p(t) / degperstep , v(t), step(t) , a(t)

treg(t)=degperstep / ( TIMERPERIOD * v(t))
#plot [t=0:(t1+t2)] treg(t)
#set y2range [0:1.1*vf]
#set y2tics border
#set parametric
#plot [t=0:(t1+t2)] step(t), treg(t), step(t), v(t) axis x1y2

# Sigmoid form
ef=10 # shape of the sigmoid, larger ef makes it sharper
svnorm(t)=1 / (1 + exp(-(ef*t - (ef/2))))
totaltime=2.0
vf=1440
sv(t) = vi + (vf - vi) * (1 / (1+exp(-(((ef/totaltime)*t-(ef/2))))))
sa(t) = (vf - vi) * (ef/totaltime) * exp(-(((ef/totaltime)*t-(ef/2)))) / ((1+exp(-(((ef/totaltime)*t-(ef/2)))))**2)
sp(t) = vi*t + (vf - vi) * (1 /(ef/totaltime)) * log (1 + exp((ef/totaltime)*t - (ef/2)))
sstep(t) = sp(t) / degperstep
streg(t)=degperstep / ( TIMERPERIOD * sv(t))
#set y2range [0:tregmin]
#set y2tics border
#plot [t=0:totaltime] sv(t), sa(t), sstep(t), streg(t) axis x1y2
#set y2range [0:1.1*vf]
#set y2tics border
#set parametric
#plot [t=0:totaltime] sstep(t), streg(t), sstep(t), sv(t) axis x1y2
invsv(t) = (1+exp(-(((ef/totaltime)*t-(ef/2))))) / (vf + vi * exp(-(((ef/totaltime)*t-(ef/2)))))
#set parametric
#plot [t=0:totaltime] sstep(t), (degperstep * invsv(t)) / TIMERPERIOD
# another form, plotting separate components
#plot [t=0:totaltime] (degperstep / TIMERPERIOD) * 1 / (vf + vi * exp(-(((ef/totaltime)*t-(ef/2))))) , (degperstep / TIMERPERIOD) * 1 / (vi + vf * exp(+(((ef/totaltime)*t-(ef/2)))))
set parametric
plot [t=0:totaltime] sstep(t), (degperstep / TIMERPERIOD) * 1 / (vf + vi * exp(-(((ef/totaltime)*t-(ef/2))))) , sstep(t), (degperstep / TIMERPERIOD) * 1 / (vi + vf * exp(+(((ef/totaltime)*t-(ef/2)))))

# Linear form
lvnorm(t) = t
lv(t)=vi+((vf-vi)*(t/totaltime))
la(t)=(vf-vi)/totaltime
lp(t)=vi*t+((vf-vi)*((t**2)/(2*totaltime)))
lstep(t)=lp(t) / degperstep
ltreg(t)=degperstep/(TIMERPERIOD * lv(t))
#set y2range [0:tregmin]
#set y2tics border
#plot [t=0:totaltime] lv(t), la(t), lstep(t), ltreg(t) axis x1y2
#set y2range [0:1.1*vf]
#set y2tics border
#set parametric
#plot [t=0:totaltime] lstep(t), ltreg(t), lstep(t), lv(t) axis x1y2

#per(t)=(360*totaltime) / ((totaltime*vi) + ((vf -vi)*t))
#st(t)=(steps360*t/2)*((vi/360) + (1/per(t)))